﻿using AutoMapper;
using MediatR;
using T.S.BaseData.Api.AppClinet.Commend.SlaugHter;
using T.S.BaseData.Api.Dto.Slaughter;
using T.S.BaseData.Domain.Entity;
using T.S.BaseData.ErrorCode;
using T.S.BaseData.Infrastructure.Base;

namespace T.S.BaseData.Api.AppClinet.CommendHand.SlaugHter
{
    public class SlaugHteringentGetCommandHandle : IRequestHandler<SlaugHteringentGetCommand, ApiResult<List<GetSlaughtergentDto>>>
    {
        private readonly IBaseRepository<SlaughteringEnterprises> slaugEntRepop;
        private readonly IMapper mapper;

        public SlaugHteringentGetCommandHandle(IBaseRepository<SlaughteringEnterprises> slaugEntRepop, IMapper mapper)
        {
            this.slaugEntRepop = slaugEntRepop;
            this.mapper = mapper;
        }

        public Task<ApiResult<List<GetSlaughtergentDto>>> Handle(SlaugHteringentGetCommand request, CancellationToken cancellationToken)
        {

            ApiResult<List<GetSlaughtergentDto>> result = new ApiResult<List<GetSlaughtergentDto>>();

            var slaugEnt = slaugEntRepop.GetAll().Where(x=>x.GoodsId == request.GoodsId);

            var model = mapper.Map<List<GetSlaughtergentDto>>(slaugEnt);

            result.Code = ApiEnums.Success;
            result.Data = model;
            result.Meg = "显示成功";

            return Task.FromResult(result);
        }
    }
}
